package com.fc.mall.portal.controller;

import com.fc.mall.base.object.Result;
import com.fc.mall.model.UmsMember;
import com.fc.mall.model.UmsWithdraw;
import com.fc.mall.portal.dto.WithdrawCreate;
import com.fc.mall.portal.service.UmsMemberService;
import com.fc.mall.portal.service.UmsWithdrawService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

@Validated
@RestController
@Api(tags = "UmsWithdrawController", description = "会员提现管理")
@RequestMapping("/member/withdraw")
public class UmsWithdrawController {

    @Autowired
    private UmsMemberService memberService;

    @Autowired
    private UmsWithdrawService withdrawService;

    @ApiOperation("申请提现")
    @PostMapping
    public Result withdraw(@RequestBody @Valid WithdrawCreate withdrawCreate) {
        UmsMember authMember = memberService.getCurrentMember();
        withdrawService.withdraw(authMember.getId(), withdrawCreate);
        return Result.success();
    }

    @ApiOperation("提现列表")
    @GetMapping("list")
    public Result list(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                       @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        UmsMember authMember = memberService.getCurrentMember();
        List<UmsWithdraw> list = withdrawService.list(authMember.getId(), pageNum, pageSize);
        return Result.success(list);
    }
}
